package com.education.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author 林心晨
 * @Title:
 * @Package
 * @Description:    加载静态文件
 * @date create in 4.20  9:12
 */
public class PropertiesUtil {

    private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
    private static Properties properties ;

    static{
        String fileName = "education.properties";
        properties = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8"));
        } catch (IOException e) {
            logger.error("加载静态文件" + fileName + "异常",e);
        }
    }

    /**
     * 获取properties文件
     * @param key
     * @return
     */
    public static String getProperties(String key){
        String property = properties.getProperty(key.trim());
        if (StringUtils.isBlank(property)){
            return null ;
        }
        return property.trim();
    }

    public static String getProperties(String key,String defaultKey){
        String property = properties.getProperty(key.trim(),defaultKey.trim());
        if (StringUtils.isBlank(property)){
            return null ;
        }
        return property.trim();
    }

}
